package com.ft.oa.web.development;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ft.oa.domain.customer.Customer;
import com.ft.oa.domain.development.DevNeed;
import com.ft.oa.domain.development.DevNeedInfo;
import com.ft.oa.domain.development.DevNeedIssue;
import com.ft.oa.domain.dto.ApiResult;
import com.ft.oa.domain.dto.development.ProjectCondition;
import com.ft.oa.domain.dto.development.ProjectDto;
import com.ft.oa.domain.project.ExecProject;
import com.ft.oa.domain.project.ExecProjectContract;
import com.ft.oa.domain.project.ExecProjectStage;
import com.ft.oa.domain.sys.SysUser;
import com.ft.oa.service.development.DevNeedService;
import com.ft.oa.service.sys.SysUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 研发管理-需求池接口
 */
@RestController
@RequestMapping("/dev/need")
public class DevNeedController {

    @Resource
    private DevNeedService devNeedService;
    @Resource
    private SysUserService sysUserService;
    /**
     * 需求类别
     */
    @GetMapping("/category/{type}")
    public ApiResult category(@PathVariable String type){

        List result = devNeedService.category(type);
        return ApiResult.successWithData(result);
    }

    /**
     * 售前负责人列表
     */
    @PostMapping("/preSaleList")
    public ApiResult preSaleList(@RequestBody DevNeed devNeed){

        List<SysUser> result = devNeedService.preSaleList(devNeed);
        return ApiResult.successWithData(result);
    }

    /**
     * 获取客户列表
     */
    @PostMapping("/customerList")
    public ApiResult customerList(@RequestBody DevNeed devNeed){

        List<Customer> result = devNeedService.customerList(devNeed);
        return ApiResult.successWithData(result);
    }

    /**
     * 获取项目列表
     */
    @PostMapping("/projectList")
    public ApiResult projectList(@RequestBody DevNeed devNeed){

        List<ExecProject> result = devNeedService.projectList(devNeed);
        return ApiResult.successWithData(result);
    }

    /**
     * 立项通过项目分页
     */
    @PostMapping("/projectPage")
    public ApiResult projectPage(@RequestBody ProjectCondition condition){

        Page<ExecProject> result = devNeedService.projectPage(condition);
        return ApiResult.successWithData(result);
    }

    /**
     * 立项通过项目详情
     */
    @PostMapping("/projectView/{projectNumber}")
    public ApiResult projectView(@PathVariable String projectNumber){
        List<ExecProjectStage> execProjectStageList = devNeedService.projectView(projectNumber);
        return ApiResult.successWithData(execProjectStageList);
    }

    /**
     * 新增需求
     */
    @PostMapping("/add")
    public ApiResult add(@RequestBody DevNeed devNeed){

        ApiResult result = devNeedService.add(devNeed);
        return result;
    }

    /**
     * 创建研发需求
     */
    @PostMapping("/createDevNeed")
    public ApiResult createDevNeed(@RequestBody List<DevNeedInfo> infos){

        devNeedService.createDevNeed(infos);
        return ApiResult.simpleSuccess();
    }

    /**
     * 项目创建需求
     */
    @PostMapping("/projectToNeed")
    public ApiResult projectToNeed(@RequestBody DevNeed devNeed){

        ApiResult result = devNeedService.projectToNeed(devNeed);
        return result;
    }

    /**
     * 项目创建需求-项目信息
     */
    @PostMapping("/projectInfo")
    public ApiResult projectInfo(@RequestBody ExecProject project){

        ProjectDto projectDto = devNeedService.projectInfo(project);
        return ApiResult.successWithData(projectDto);
    }

    /**
     * 编辑需求
     */
    @PostMapping("/edit")
    public ApiResult edit(@RequestBody DevNeed devNeed){

        ApiResult result = devNeedService.edit(devNeed);
        return result;
    }


    /**
     * 需求分页
     */
    @PostMapping("/page")
    public ApiResult del(@RequestBody DevNeed devNeed){

        Page<DevNeed> page = devNeedService.page(devNeed);

        return ApiResult.successWithData(page);
    }

    /**
     * 删除需求
     * @param id
     * @return
     */
    @PostMapping("/del/{id}")
    public ApiResult del(@PathVariable Long id){

        devNeedService.del(id);

        return ApiResult.simpleSuccess();
    }


    /**
     * 需求确认
     */
    @PostMapping("/confirm")
    public ApiResult confirm(@RequestBody DevNeed devNeed){

        ApiResult result = devNeedService.confirm(devNeed);

        return result;
    }


    /**
     * 需求驳回
     */
    @PostMapping("/reject")
    public ApiResult reject(@RequestBody DevNeed devNeed){

        devNeedService.reject(devNeed);

        return ApiResult.simpleSuccess();
    }

    /**
     * 需求关闭
     */
    @PostMapping("/close")
    public ApiResult close(@RequestBody DevNeed devNeed){

        devNeedService.close(devNeed);

        return ApiResult.simpleSuccess();
    }

    /**
     * 需求整合下发
     */
    @PostMapping("/issue")
    public ApiResult issue(@RequestBody DevNeed devNeed){

        ApiResult result = devNeedService.issue(devNeed);

        return result;
    }

    /**
     * 需求拆分
     */
    @PostMapping("/issueRollback")
    public ApiResult issueRollback(@RequestBody DevNeedIssue issue){

        ApiResult result = devNeedService.issueRollback(issue);

        return result;
    }

    /**
     * 已下发需求-条件分页
     */
    @PostMapping("/issued/page")
    public ApiResult issuedPage(@RequestBody DevNeed condition){

        Page<DevNeedIssue> result = devNeedService.issuedPage(condition);

        return ApiResult.successWithData(result);
    }

    /**
     * 需求下发-条件分页
     */
    @PostMapping("/issue/page")
    public ApiResult issuePage(@RequestBody DevNeed devNeed){

        Page<DevNeed> result = devNeedService.issuePage(devNeed);

        return ApiResult.successWithData(result);
    }
    /**
     * 编辑需求下发已下发列
     */
    @PostMapping("/issue/edit")
    public ApiResult issueEdit(@RequestBody DevNeedIssue devNeedIssue){

        ApiResult result = devNeedService.issueEdit(devNeedIssue);
        return result;
    }
    /**
     * 需求分析-查询点击确认用户列表
     */
    @PostMapping("/userList")
    public ApiResult userList(){
        List<SysUser> result = sysUserService.listAll();
        return ApiResult.successWithData(result);
    }


    /**
     * 需求收集-已录入详情接口
     */
    @PostMapping("/devNeedDetail")
    public ApiResult devNeedDetail(@RequestBody DevNeed devNeed){
        DevNeed result = devNeedService.devNeedDetail(devNeed);
        return ApiResult.successWithData(result);
    }
    /**
     * 需求收集-已同步详情接口
     */
    @PostMapping("/devNeedProjectDetail")
    public ApiResult devNeedProjectDetail(@RequestBody ExecProject execProject){
        List<DevNeed>  result = devNeedService.devNeedProjectDetail(execProject);
        return ApiResult.successWithData(result);
    }

    @PostMapping("/needNo")
    public ApiResult needNo(@RequestBody DevNeed devNeed){
        String s = devNeedService.needNo(devNeed);
        return ApiResult.successWithData(s);
    }
}
